<template>
	<view>
		<van-tabs @change="changeTab" color="#1152FC" animated :lazy-render="false" :active="active">
			<van-tab :title-style="active == 0 ? 'color: #1152FC' : ''" :title="`进行中(${handleLength})`">
				<view v-if="handleList.length" class="bg100">
					<task-list  :taskList="handleList"></task-list>
				</view>
				
				<view v-else>
					<van-empty description="暂无记录" />
				</view>
				<uni-load-more v-if="handleList.length >= 10" :status="status" />
			</van-tab>
			<van-tab :title-style="active == 1 ? 'color: #1152FC' : ''" :title="`已超时(${overTimeLength})`">
				<view v-if="overTimeList.length" class="bg100">
					<task-list  :taskList="overTimeList"></task-list>
				</view>
				
				<view v-else>
					<van-empty description="暂无记录" />
				</view>
				<uni-load-more v-if="overTimeList.length >= 10" :status="status1" />
			</van-tab>
			<van-tab :title-style="active == 2 ? 'color: #1152FC' : ''" :title="`已完成(${completeLength})`">
				<view v-if="completeList.length" class="bg100">
					<task-list  :taskList="completeList"></task-list>
				</view>
				
				<view v-else>
					<van-empty description="暂无记录" />
				</view>
				<uni-load-more v-if="completeList.length >= 10" :status="status2" />
			</van-tab>
		</van-tabs>
	</view>
</template>

<script>
	import TaskList from '@/components/taskList.vue'
	// import RecordItem from '../components/recordItem.vue'
	export default {
		components: {
			TaskList
		},
		data() {
			return {
				handleList: [],
				overTimeList: [],
				completeList: [],
				status: 'more',
				status1: 'more',
				status2: 'more',
				handleLength: 0,
				overTimeLength: 0,
				completeLength: 0,
				haveMoreHandle: true,
				haveMoreOver: true,
				haveMoreComplete: true,
				active: 0,
				params: {
					来源: "fitment",
					执行人id: uni.getStorageSync('userInfo').id,
					任务类型: null,
					任务状态: 2,
					isAll: 1,
					pagination: {
						current: 1,
						pageSize: 10
					},
					sorter: {
						field: "created_at",
						order: 0
					}
				},
				params1: {
					来源: "fitment",
					执行人id: uni.getStorageSync('userInfo').id,
					任务类型: null,
					任务状态: 3,
					isAll: 1,
					pagination: {
						current: 1,
						pageSize: 10
					},
					sorter: {
						field: "created_at",
						order: 0
					}
				},
				params2: {
					来源: "fitment",
					执行人id: uni.getStorageSync('userInfo').id,
					任务类型: null,
					任务状态: 4,
					isAll: 1,
					pagination: {
						current: 1,
						pageSize: 10
					},
					sorter: {
						field: "created_at",
						order: 0
					}
				},
				recordList: [{
					id: 1,
					申请人: '123',
					申请单位: '奥声物业',
					申请仓库: '太平仓库',
					备注: '需要使用'
				},{
					id: 2,
					申请单位: '奥声物业',
					申请人: '123',
					申请仓库: '太平仓库',
					备注: '需要使用'
				}]
			}
		},
		onLoad() {
			this.getHandleList()
			this.getOverTimeList()
			this.getCompleteList()
		},
		onReachBottom() {
			if (this.active === 0 && this.haveMoreHandle) {
				this.status = 'loading'
				this.params.pagination.current++
				this.getHandleList()
			} else if (this.active === 1 && this.haveMoreOver) {
				this.status1 = 'loading'
				this.params1.pagination.current++
				this.getOverTimeList()
			} else if(this.active === 2 && this.haveMoreEmerge) {
				this.status2 = 'loading'
				this.params2.pagination.current++
				this.getCompleteList()
			}
		},
		methods: {
			changeTab(name, title) {
				this.active = name.target.index
			},
			getHandleList() {
				this.$http.post('taskSystem/task/list', this.params).then(res => {
					if (res.code === 10000) {
						console.log(res)
						this.handleLength = res.data.total
						res.data.list = res.data.list || []
						this.handleList = [...this.handleList, ...res.data.list]
						if(this.handleList.length >= res.data.total) {
							this.haveMoreHandle= false
							this.status = 'noMore'
						}
						// this.nostartLength = res.data.total
						// res.data.list = res.data.list || []
						// this.nostartList = [...this.nostartList, ...res.data.list]
						// if(this.nostartList.length >= res.data.total) {
						// 	this.haveMoreNoStart = false
						// 	this.status = 'noMore'
						// }
					}
				})
			},
			getOverTimeList() {
				this.$http.post('taskSystem/task/list', this.params1).then(res => {
					if (res.code === 10000) {
						// console.log(res)
						this.overTimeLength = res.data.total
						res.data.list = res.data.list || []
						this.overTimeList = [...this.overTimeList, ...res.data.list]
						if(this.overTimeList.length >= res.data.total) {
							this.haveMoreOver= false
							this.status1 = 'noMore'
						}
					}
				})
			},
			getCompleteList() {
				this.$http.post('taskSystem/task/list', this.params2).then(res => {
					if (res.code === 10000) {
						// console.log(res)
						this.completeLength = res.data.total
						res.data.list = res.data.list || []
						this.completeList = [...this.completeList, ...res.data.list]
						if(this.completeList.length >= res.data.total) {
							this.haveMoreComplete= false
							this.status2 = 'noMore'
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss">
.bg100 {
		overflow: hidden;
		// padding-top: 20rpx;
		background-color: #f5f5f5;
		min-height: 100vh;
}
</style>
